package com.fivetalks.client;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

import com.fivetalks.network.Definition;

public class SocketClient{
	private static SocketClient instance = null;
	ChatLobbyActivity chatLobbyActivity;
	RoomDialogActivity roomDialogActivity;
	PreChatActivity preChatActivity;
	ChattingActivity chattingActivity;
	ArrowFormActivity arrowFormActivity;
	ArrowResultView arrowResultView;
	SettingActivity settingActivity;
	LoveRoomActivity loveRoomActivity;
	
	public static SocketClient getInstance(
			ChatLobbyActivity chatLobbyActivity, 
			RoomDialogActivity roomDialogActivity,
			PreChatActivity preChatActivity, 
			ChattingActivity chattingActivity,
			ArrowFormActivity arrowFormActivity,
			ArrowResultView arrowResultView,
			SettingActivity settingActivity,
			LoveRoomActivity loveRoomActivity){
		if(instance == null){
			instance = new SocketClient( );
		}
		//instance.open();
		instance.chatLobbyActivity = chatLobbyActivity;
		instance.roomDialogActivity = roomDialogActivity;
		instance.preChatActivity = preChatActivity;
		instance.chattingActivity = chattingActivity;
		instance.arrowFormActivity = arrowFormActivity;
		instance.arrowResultView = arrowResultView;
		instance.settingActivity = settingActivity;
		instance.loveRoomActivity = loveRoomActivity;
		return instance;
	}
	private SocketClient(){

		open();
		ChatThread ct = new ChatThread(this);
		ct.start();
	}
	private void open() {
		try{
			this.socket = new Socket(Definition.URL, Definition.PORT);
			dos = new DataOutputStream(socket.getOutputStream());
			dis = new DataInputStream(socket.getInputStream());
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void close(){
		try {
			dis.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			dos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private Socket socket;
	private DataInputStream dis =null;
	private DataOutputStream dos = null;
	private long userId;
	private String nickName;
	private int age;
	private String gender;
	private String password;
	private String email;
	
	
	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Socket getSocket() {
		return socket;
	}
	public void setSocket(Socket socket) {
		this.socket = socket;
	}
	public DataInputStream getDis() {
		return dis;
	}
	public void setDis(DataInputStream dis) {
		this.dis = dis;
	}
	public DataOutputStream getDos() {
		return dos;
	}
	public void setDos(DataOutputStream dos) {
		this.dos = dos;
	}
	public long getUserId() {
		return userId;
	}
	public void setUserId(long userId) {
		this.userId = userId;
	}
	public String getNickName() {
		return nickName;
	}
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	
	

}
